var checkedFalseProjectStore = null;
var checkedFalsePremisesStore = null;
var checkedFalseBuildingStore = null;
var checkedFalseUnitStore = null;
var checkedFalseRoomStore = null;

Ext.define('component.marketing.re_checked_false', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
		
		//项目
		checkedFalseProjectStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "projectName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/estate/project/findProjectList?needAuth=T&resourcesCode=menu_0003_0001',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              }
	        } ,
	        autoLoad: false
		});
		checkedFalseProjectStore.load({
			callback:function(records, options, success){
				var count = checkedFalseProjectStore.getCount();
				if(count>0){
					var id = checkedFalseProjectStore.getAt(0).get("id");
					Ext.getCmp('checkedFalseProjectStore').setValue(id)
				}
				if(Ext.Array.contains(idata,"fin:list:all")){
					var data = {"projectName": "全部", "id": '-1'};
					var rs = Ext.create(data);
					checkedFalseProjectStore.insert(count+1, rs);
				}
				//userList.load();
			}
		});
		//组团
		checkedFalsePremisesStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "groupName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectPremises/findPremisesList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		
		checkedFalsePremisesStore.on("beforeload", function(){
			checkedFalsePremisesStore.removeAll();
			checkedFalseBuildingStore.removeAll();
			checkedFalseUnitStore.removeAll();
			checkedFalseRoomStore.removeAll();
			Ext.getCmp("checkedFalsePremisesStore").setValue("");
			Ext.getCmp("checkedFalseBuildingStore").setValue("")
			Ext.getCmp("checkedFalseUnitStore").setValue("")
			Ext.getCmp("checkedFalseRoomStore").setValue("")
			var projectId = Ext.getCmp("checkedFalseProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			checkedFalsePremisesStore.proxy.extraParams.projectId = projectId;
		});
		//楼栋
		checkedFalseBuildingStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "buildingName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectBuilding/findBuildingList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		checkedFalseBuildingStore.on("beforeload", function(){
			checkedFalseBuildingStore.removeAll();
			checkedFalseUnitStore.removeAll();
			checkedFalseRoomStore.removeAll();
			Ext.getCmp("checkedFalseBuildingStore").setValue("")
			Ext.getCmp("checkedFalseUnitStore").setValue("")
			Ext.getCmp("checkedFalseRoomStore").setValue("")
			var projectId = Ext.getCmp("checkedFalseProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			var premisesId = Ext.getCmp("checkedFalsePremisesStore").getValue();
			checkedFalseBuildingStore.proxy.extraParams.projectId = projectId;
			checkedFalseBuildingStore.proxy.extraParams.premisesId = premisesId;
		});
		//单元
		checkedFalseUnitStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "unitName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectUnit/findUnitList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		checkedFalseUnitStore.on("beforeload", function(){
			checkedFalseUnitStore.removeAll();
			checkedFalseRoomStore.removeAll();
			Ext.getCmp("checkedFalseUnitStore").setValue("")
			Ext.getCmp("checkedFalseRoomStore").setValue("")
			var projectId = Ext.getCmp("checkedFalseProjectStore").getValue();
			if("-1" == projectId){
				projectId = "";
			}
			var premisesId = Ext.getCmp("checkedFalsePremisesStore").getValue();
			var buildingId = Ext.getCmp("checkedFalseBuildingStore").getValue();
			checkedFalseUnitStore.proxy.extraParams.projectId = projectId;
			checkedFalseUnitStore.proxy.extraParams.premisesId = premisesId;
			checkedFalseUnitStore.proxy.extraParams.buildingId = buildingId;
		});
		//房间
		checkedFalseRoomStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "roomName"],
	        proxy:{
	   			type:'ajax',
	            url:contextPath+'/estate/projectRoom/findRoomList',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              	}
	        } ,
	        autoLoad: false
		});
		
		var form_false = Ext.create("Ext.form.Panel", {
			//minHeight:170,
		    title: "查询条件",
		    collapsible: true,  //可折叠
		    autoScroll: false,   //自动创建滚动条
		    defaultType: 'textfield',
		    defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
		    items: [
				{
				    xtype: "container",
				    layout: "hbox",
				    items: [
						{  
				            xtype:'combobox',
				            id:'checkedFalseProjectStore',
				            name: "projectId",
				            store: checkedFalseProjectStore,
				            valueField: "id",  
				            displayField: "projectName",
				            fieldLabel:'所属项目',
				            queryMode:'local',
				            typeAhead: true,
				            labelAlign:'right',
				            listeners:{
				            	'change':function(value){
				            		//加载组团数据
				            		if(value.lastValue && value.lastValue != "-1"){
				            			checkedFalsePremisesStore.load({
				            				callback: function(records, operation, success){
				            					//若无组团数据，加载楼栋
				            					var recordLen = records.length;
				            					if(recordLen == 0){
				            						checkedFalseBuildingStore.load();
				            					}
				            				}
				            			});
				            		}else{
				            			checkedFalsePremisesStore.removeAll();
				            			checkedFalseBuildingStore.removeAll();
				            			checkedFalseUnitStore.removeAll();
				            			checkedFalseRoomStore.removeAll();
				            			Ext.getCmp("checkedFalsePremisesStore").setValue("");
				            			Ext.getCmp("checkedFalseBuildingStore").setValue("")
				            			Ext.getCmp("checkedFalseUnitStore").setValue("")
				            			Ext.getCmp("checkedFalseRoomStore").setValue("")
				            		}
				            		//userList.load();
				            	}
				            }
				        },
						{  
				            xtype:'combobox',
				            id:'checkedFalsePremisesStore',
				            name: "premisesId",
				            store: checkedFalsePremisesStore,
				            valueField: "id",  
				            displayField: "groupName",
				            queryMode:'local',
				            typeAhead: true,
				            listeners:{
				            	'change':function(value){
				            		//加载楼栋
				            		//若无楼栋数据，加载单元
				            		if(value.lastValue && value.lastValue != "-1"){
				            			checkedFalseBuildingStore.load({
				            				callback: function(records, operation, success){
				            					//若无组团数据，加载楼栋
				            					var recordLen = records.length;
				            					if(recordLen == 0){
				            						checkedFalseUnitStore.load();
				            					}
				            				}
				            			});
				            		}
				            	}
				            }
				        },
						{  
				            xtype:'combobox',
				            id:'checkedFalseBuildingStore',
				            name: "buildingId",
				            store: checkedFalseBuildingStore,
				            valueField: "id",  
				            displayField: "buildingName",
				            queryMode:'local',
				            typeAhead: true,
				            listeners:{
				            	'change':function(value){
				            		//加载单元
				            		//若无单元数据，加载房间
				            		if(value.lastValue && value.lastValue != "-1"){
				            			checkedFalseUnitStore.load({
				            				callback: function(records, operation, success){
				            					//若无组团数据，加载楼栋
				            					var recordLen = records.length;
				            					if(recordLen == 0){
				            						checkedFalseRoomStore.load();
				            					}
				            				}
				            			});
				            		}
				            	}
				            }
				        },
						{  
				            xtype:'combobox',
				            id:'checkedFalseUnitStore',
				            name: "unitId",
				            store: checkedFalseUnitStore,
				            valueField: "id",  
				            displayField: "unitName",
				            queryMode:'local',
				            typeAhead: true,
				            listeners:{
				            	'change':function(value){
				            		//加载房间
				            		if(value.lastValue && value.lastValue != "-1"){
				            			checkedFalseRoomStore.load();
				            		}
				            	}
				            }
				        },
						{  
				            xtype:'combobox',
				            id:'checkedFalseRoomStore',
				            name: "roomId",
				            store: checkedFalseRoomStore,
				            valueField: "id",  
				            displayField: "roomName",
				            queryMode:'local',
				            typeAhead: true
				        }
					]
				},  
	            {
		            xtype: "container",
		            layout: "hbox",
		            items: [{ xtype: "hiddenfield", name: "reChecked", value: "1"},
	                    { xtype: "hiddenfield", name: "result", value: "0"},
	                    { xtype: "textfield", name: "relationCode", fieldLabel: "业务编号", labelWidth:100, labelAlign:'right'},
	                    {  
	  	                  xtype:'combobox',
	  	 		    	  fieldLabel:'业务标志',
	  	 		    	  store:businessFlagEnum,
	  	 		    	  displayField: "value",
	  	 		    	  valueField:"id",
	  	 		    	  name:'businessFlag',
	  	 		    	  queryMode:'local',
	  				      typeAhead: true,
	  				      labelAlign:'right',
	  				      labelWidth:100
	          	        }
	            ]
            },{
	            xtype: "container",
	            layout: "hbox",
	            items: [
	              /*  { xtype: "textfield", name: "billCode", fieldLabel: "票据号码", labelWidth:90,labelAlign:'right'},*/
		            {  
			            xtype:'combobox',  
			            name:'statementId', 
			            store: billUser,
			            displayField: "userName",           
			            valueField: "id",  
			            fieldLabel:'结算人员',  
			            queryMode:'local',
			            typeAhead: true,
			            labelAlign:'right',
			            labelWidth:100
			        },{  
		                  xtype:'combobox',
		 		    	  fieldLabel:'结算方式',
		 		    	  store:statementTypeEnum,
		 		    	  displayField: "value",
		 		    	  valueField:"id",
		 		    	  name:'statementType',
		 		    	  queryMode:'local',
					      typeAhead: true,
					      labelAlign:'right',
					      labelWidth:100
        	        },{  
					      xtype:'combobox',
						  fieldLabel:'银行账号',
						  store:getBankAccount,
						  displayField: "dictionaryName",
						  valueField:"dictionaryName",
						  name:'bankAccount',
						  queryMode:'local',
						  typeAhead: true,
						  labelAlign:'right',
						  labelWidth:100,
        	        }
	            ]
            },{
	            xtype: "container",
	            layout: "hbox",
	            items: [
        	        {
		            	xtype:'container',
		            	layout:'hbox',
		            	items:[{
		            		xtype:'datefield',
			                fieldLabel:'开始结算日期',
			                name:'jsDateStart',
			                format: 'Y-m-d',
				              labelAlign:'right',
				              labelWidth:100

		            	},{
		            		xtype:'datefield',
		            		fieldLabel:'结束结算日期',
		            		name:'jsDateEnd',
				            labelAlign:'right',
				            format: 'Y-m-d',
				            labelWidth:100
		            	}]
		            }
	            ]
            },{
	            xtype: "container",
	            layout: "hbox",
	            items: [
	                	{ 
							xtype: "checkboxgroup",
							id:'busStatus_false',
							fieldLabel: "业务类型",
							name :"receivablesType",
							labelAlign:'right',
							labelWidth:100,
							width:400,
							items:[{
						    		boxLabel:'认筹',
						    		inputValue:'0'
						    	},{
						    		boxLabel:'认购',
						    		inputValue:'1'
						    	},{
						    		boxLabel:'签约',
						    		inputValue:'2'
						    	},{
						    		boxLabel:'面积补差',
						    		inputValue:'3'
						    	}
						     ]
						}
	            ]
            },{
	            xtype: "container",
	            layout: "hbox",
	            items: [
                    { xtype: "textfield", name: "billCode", fieldLabel: "票据号码", labelWidth:100,labelAlign:'right'},
                    { xtype: "textfield", name: "customer_name", fieldLabel: "客户名称", labelWidth:100, labelAlign:'right'}
	            ]
            }
            
	        ],
		    buttons: [
	  	        { xtype: "button", text: "查询", 
	  	        	handler:function(){
	  	        		//获取通过checkboxgroup定义的checkbox值
	  	        		//业务状态
	  	        		var busStatusValue = Ext.getCmp('busStatus_false').getChecked();
	  	        		var busStatus="";
	  	        		Ext.Array.each(busStatusValue, function(item){
	  	        			busStatus += item.inputValue+',' ;
	  	        		});
	  	        		gridStore_false.getProxy().extraParams.receivablesType = busStatus;
	  	        		//gridStore_false.load();
	  	        		var pagingTool=Ext.getCmp("pagingTool2");
	  	        		pagingTool.moveFirst();//跳至第一页
	  	        	}  
	  	        },
	  	        { xtype: "button", text: "清空",handler:function(){
	  	        		form_false.getForm().reset();
	  	        	}
	  	        }
	  	    ]
	});
		
	if(payDepositOff=='true')
		 Ext.getCmp('busStatus_false').items.items[0].hide();
	
	var gridStore_false = Ext.create('Ext.data.Store', {
        fields: ["relationId", "businessType", "relationCode", "customer_name", "combined_name", "calculatArea", "price", "totalPrice", "relationType",
                 "businessType", "realAmount", "billCode", "statement", "bankAccount", "checked_name", "checkDate", "remark","receivablesType"],
        pageSize: 10,  //页容量15条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        proxy: {
            type: 'ajax',
            url: jypath+'/marketing/haveReceiveRefund/re_checked_list?resourcesCode=menu_0003_0001',
            actionMethods: { read: 'POST' },
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        autoLoad: true  //即时加载数据
    });
	
	gridStore_false.on("beforeload",function(){
        Ext.apply(gridStore_false.proxy.extraParams,form_false.getForm().getValues());
        var projectId = Ext.getCmp("checkedFalseProjectStore").getValue();
        if(projectId == "-1"){
        	gridStore_false.proxy.extraParams.projectId = "";
        }
        var newResCode = "menu_0003_0001";
        gridStore_false.proxy.extraParams.resourcesCode = newResCode;
    });
	
	var grid_false = Ext.create('Ext.grid.Panel', {
		minHeight:450,
		minWidth:300,
        store: gridStore_false,
        columnLines: true,
        columns: [{
            text     : '业务编号', 
            dataIndex: 'relation',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var rec = grid_false.getStore().getAt(rowIndex);
            	var url = "";
            	var receivablesType=rec.get('receivablesType');
            	if(receivablesType == "0"){
            		//认筹
            		url = jypath+"/customer/payDeposit/toView?id="+rec.get('relationId')+"&returnUrl=,marketing,haveReceiveRefund,index";
            	}else if(receivablesType == "1"){
            		//认购
            		url = jypath+"/customer/subscribe/toView?id="+rec.get('relationId')+"&returnUrl=,marketing,haveReceiveRefund,index";
            	}else if(receivablesType == "2"){
            		//签约
            		url = jypath+"/customer/signed/toView?id="+rec.get('relationId')+"&returnUrl=,marketing,haveReceiveRefund,index";
            	}else if(receivablesType == "3"){
            		//面积补差
            		url = jypath+"/marketing/reserveArea/reserveAreaDetail?id="+rec.get('relationId')+"&returnUrl=,marketing,haveReceiveRefund,index";
            	}
	        	var html = '<a href="'+url+'" style="cursor:pointer">'+rec.get('relationCode')+'</a>';
	        	return html;
	        }
        },{
            text     : '客户名称', 
            dataIndex: 'customer_name'
        },{
            text     : '房号',
            dataIndex: 'combined_name',
        },{
            text     : '签约面积(㎡)',
            dataIndex: 'calculatArea'
        },{
            text     : '签约单价(元)',
            dataIndex: 'price'
        },{
            text     : '签约金额(元)',
            dataIndex: 'totalPrice'
        },{
            text     : '房款类型',
            dataIndex: 'relationType'
        },{
            text     : '业务标志',
            dataIndex: 'businessType'
        },{
            text     : '发生额',
            dataIndex: 'realAmount'
        },{
            text     : '票据号码',
            dataIndex: 'billCode'
        },{
            text     : '结算日期/结算人员/结算方式',
            dataIndex: 'statement'
        },{
            text     : '结算银行',
            dataIndex: 'bankAccount'
        },{
            text     : '备注',
            dataIndex: 'remark'
        },{  
            text : "操作",  
	        dataIndex: 'actioncolumn',
	        renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
	        	var rec = grid_false.getStore().getAt(rowIndex);
	        	var url = jypath + "/marketing/haveReceiveRefund/re_checked_view?id="+rec.get('id');
	        	if(finNeedReceiveCheck==false){
	        		var html = '<a href="'+url+'">复核</a>';
		        	return html;
	        	}
	        
	        }
        }],
        title: '已复核未通过',
        dockedItems: [{  
            xtype: 'pagingtoolbar',  
            store: gridStore_false,   // GridPanel中使用的数据  
            dock: 'bottom',  
            displayInfo: true,  
            emptyMsg:"没有数据",  
            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据",
            id:'pagingTool2'
        }
        ]
    });
	
		
		var defaultConfig_false = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
				items:[form_false,grid_false]
		};
		Ext.apply(this,defaultConfig_false);
		this.callParent(arguments);
		
	}
});

function dateFormat(value){ 
    if(null != value){ 
        return Ext.Date.format(new Date(value),'Y-m-d'); 
    }else{ 
        return null; 
    } 
} 
